'use strict';

module.exports = {
  /**
   * Message Box while redirect after operation
   * @param strTitle
   * @param strContent
   * @param strRediret
   * @param targetURL
   * @param bAuto
   * @param strStyle
   * @return {Promise<void>}
   */
  async redirectMessage(
    strTitle, strContent, strRediret, targetURL, bAuto, strStyle) {
    if (strStyle === undefined) {
      strStyle = 'messagebox';
    }

    let data = {
      strTitle,
      strContent,
      strRediret,
      targetURL,
      bAuto,
      strStyle,
    };

    await this.ctx.render('message.ejs', data);
  },

  // Debug Output
  debug(obj) {
    /*write("<div style='color:#003399; border: solid 1px #003399; background: #EEF7FF; margin: 1px; font-size: 12px; padding: 2px;'>");
    if(obj&&obj.constructor){
      write("<b>"+String(obj.constructor).match(/function (\w+)\(/)[1]+((obj.constructor==String||obj.constructor==Array)?"["+obj.length+"]":"")+":</b> ");
    }
    write(obj);
    write("</div>");*/
  },

// SQL Debug Output
  showSQL() {
    /*write("<div style='margin: 10px;width: 100%'><div><table style='background: #CCCCCC; font-size: 12px;' width='100%' cellpadding='3' cellspacing='1'>");
    write("<tr><th>SQL: "+connBlog.queryCount+" queries</th><th>Return</th><th>Total</th></tr>");
    for(var i=0;i<connBlog.debugData.length;i++){
      write("<tr style='background:#FCFCFC'><td>"+Server.HTMLEncode(connBlog.debugData[i][0])+"</td><td>"+connBlog.debugData[i][1]+"</td><td>"+connBlog.debugData[i][2]+"</td></tr>")
    }
    write("</table></div></div>");*/
  },

// Fatal Error Output
  errorMessage(err) {
    /*write("<div style='color:#990000; border: solid 1px #CC0000; background: #FFEEDD; margin: 1px; font-size: 12px;'>");
    if(err.constructor==Error){
      write("<div style='color:#FFFFFF; padding: 2px; background: #990000;'>Error Code " + String(err.number & 0xFFFF) + "</div><div style='padding: 2px;'>"+err.description);
    }else{
      write("<div style='padding: 2px;'>"+err);
    }
    write("</div></div>");
    showSQL();
    Response.End();*/
  },
};
